from scipy.integrate import quad
from scipy.optimize import fsolve

# 定义c1关于v的函数关系
def c1(v):
    return (8.139845349685578 * (v**0) +
            0.1328532863554136 * (v**1) -
            0.044370452329027046 * (v**2) +
            0.00450530267787368 * (v**3) -
            0.0002418479879469376 * (v**4) +
            7.66924851972472e-06 * (v**5) -
            1.5081701789967263e-07 * (v**6) +
            1.8563164450661327e-09 * (v**7) -
            1.3891386770874718e-11 * (v**8) +
            5.769608703690977e-14 * (v**9) -
            1.0185281834710351e-16 * (v**10))

# 定义c2关于v的函数关系
def c2(v):
    return (-65.05999538619501 * 1 +  # 对于x=0时的特殊情况处理
            2.2948489428254444 * v -
            0.0872530119847595 * v**2 +
            0.0028711815804349375 * v**3 -
            7.535323778198846e-05 * v**4 +
            1.4808206943005465e-06 * v**5 -
            2.0873689579607042e-08 * v**6 +
            2.0239092465902265e-10 * v**7 -
            1.2716953881394252e-12 * v**8 +
            4.6365441769758436e-15 * v**9 +
            -7.416627700899087e-18 * v**10)

# 定义被积函数1
def integrand1(v):
    return v / (120 * c1(v))

# 定义被积函数2
def integrand2(x):
    # 注意这里的变量名是x，以区分integrand1的v
    return x / (120 * c2(x))

# 计算积分差值的函数
def integral_difference(v):
    val1, _ = quad(integrand1, 91.6, v)  # 从91.6到v的积分
    val2, _ = quad(integrand2, 0, v)     # 从0到v的积分
    return val1 - val2 - 4  # 返回积分差与4的差

# 定义寻找的v的初始猜测值
initial_guess = [95]

# 使用fsolve寻找使integral_difference(v)=0的v值
solution = fsolve(integral_difference, initial_guess)

print(f"求解v的值为: {solution[0]}")